local skel = fk.CreateSkill {
  name = "emo__qiji",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__qiji"] = "奇迹",
  [":emo__qiji"] = "出牌阶段限一次，你可以与一名其他角色同时选择一个属性，令其本回合受到的伤害改为此属性。若双方选择：相同，你获得其一张牌；不同，则以你为准，其本回合不能响应牌。",

  ["#emo__qiji"] = "奇迹:与一名其他角色同时选择一个属性，其本回合受到的伤害改为此属性",
  ["@emo__qiji-turn"] = "奇迹",
  ["@@emo__qiji_disable-turn"] = "奇迹:不能响应",
  ["#emo__qiji-choice"] = "选择一个属性，本回合受到的伤害改为此属性",
}

skel:addEffect("active", {
  anim_type = "control",
  prompt = "#emo__qiji",
  card_num = 0,
  target_num = 1,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0 and player ~= to_select
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local damageNatures = {}
    for k, v in pairs(Fk:getDamageNatures()) do
      table.insert(damageNatures, v[1])
    end
    if #damageNatures == 0 then return end
    local ret = room:askToJointChoice(player, {
      players = {player, to},
      prompt = "#emo__qiji-choice",
      choices = damageNatures,
    })
    local choice = ret[player]
    room:setPlayerMark(to, "@emo__qiji-turn", choice)
    if choice == ret[to] then
      if not to:isNude() then
        local cid = room:askToChooseCard(player, {
          flag = "he", target = to, skill_name = skel.name
        })
        room:obtainCard(player, cid, false, fk.ReasonPrey, player, skel.name)
      end
    else
      room:setPlayerMark(to, "@@emo__qiji_disable-turn", 1)
    end
  end,
})

skel:addEffect(fk.PreCardEffect, {
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@@emo__qiji_disable-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    data:setDisresponsive(player)
  end,
})

skel:addEffect(fk.PreDamage, {
  can_refresh = function (self, event, target, player, data)
    return data.to == player and player:getMark("@emo__qiji-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    local mark = player:getMark("@emo__qiji-turn")
    for k, v in pairs(Fk:getDamageNatures()) do
      if v[1] == mark then
        data.damageType = k
        break
      end
    end
  end,
})

return skel
